package com.usian.text;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.usian.mapper.UsersMapper;
import com.usian.pojo.Users;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.util.List;

@SpringBootTest
public class usertext {
    @Autowired
    private UsersMapper usersMapper;
//查询所有
    @Test
    public void selectAll(){
        List<Users> list = usersMapper.selectList(null);
        System.out.println(list);
    }
    //通过id查询
    @Test
    public void selectByid(){
        Users users = usersMapper.selectById(5);
        System.out.println(users);

    }
    //通过id删除
    @Test
    public void deleteid(){
        usersMapper.deleteById(1);
    }
    //添加
    @Test
    public void insert(){
        Users users=new Users();
        users.setId(5);
        users.setName("泰坦6");
        users.setAddress("19");
        usersMapper.insert(users);
    }
//修改
@Test
public void update(){
    Users users=new Users();
    users.setId(5);
    users.setName("大树");
    users.setAddress("999");
    usersMapper.updateById(users);
}
//分页查询
    @Test
    public void slelectpage(){
        Page<Users> usersPage = new Page<Users>(1, 2);
        usersMapper.selectPage(usersPage, null);
        System.out.println("当前页"+usersPage.getCurrent());
        System.out.println("页面大小"+usersPage.getSize());
        System.out.println("总条数"+usersPage.getTotal());
        System.out.println("总页数"+usersPage.getPages());
        System.out.println("当前页数狙"+usersPage.getRecords());
    }

}
